package org.example.demo10_proxy;

/**
 * 商品信息查询代理
 */
public class BusinessInfoQueryProxy implements BusinessInfoQuery {
    private RealBusinessInfoQuery realQuery;
    private int queryCount = 0;

    public BusinessInfoQueryProxy() {
        this.realQuery = new RealBusinessInfoQuery();
    }

    @Override
    public void queryInfo(String userId) {
        authenticateUser(userId); // 用户身份验证
        realQuery.queryInfo(userId); // 调用实际查询方法
        logQuery(userId); // 记录查询日志
        queryCount++;
        calculateQueryCost(); // 根据查询次数收取费用
    }

    private void authenticateUser(String userId) {
        System.out.println("Authenticating user: " + userId);
    }

    private void logQuery(String userId) {
        System.out.println("Logging query for user: " + userId);
    }

    private void calculateQueryCost() {
        System.out.println("Calculating query cost based on query count: " + queryCount);
    }
}